package com.smartboot.plus.controller;


import com.smartboot.plus.api.R;
import com.smartboot.plus.ignite.cache.MqttClientCache;
import com.smartboot.plus.page.IPage;
import com.smartboot.plus.service.MqttClientService;
import com.smartboot.plus.support.Condition;
import com.smartboot.plus.support.Query;
import com.smartboot.plus.vo.MqttClientVO;
import com.smartboot.plus.wapper.ConnectionWrapper;
import tech.smartboot.feat.cloud.annotation.Autowired;
import tech.smartboot.feat.cloud.annotation.Controller;
import tech.smartboot.feat.cloud.annotation.Param;
import tech.smartboot.feat.cloud.annotation.RequestMapping;


@Controller("connections")
public class ConnectionController {

    @Autowired
    private MqttClientService mqttClientService;


    /**
     * 分页
     *
     * @param clientId
     * @param userName
     * @param query
     * @return
     */
    @RequestMapping("/page")
    public R<IPage<MqttClientVO>> page(@Param("clientId") String clientId,
                                       @Param("userName") String userName,
                                       Query query) {
        IPage<MqttClientCache> page = mqttClientService.selectPage(Condition.getPage(query), clientId, userName);
        IPage<MqttClientVO> clientVOIPage = ConnectionWrapper.build().pageVO(page);
        return R.data(clientVOIPage);
    }


    @RequestMapping("/disconnection")
    public R<Object> disconnection(@Param("clientId") String clientId) {
        return R.status(mqttClientService.disconnection(clientId));
    }


}
